package com.example.demo.control;

import com.example.demo.others.git.GitUtil;
import com.example.demo.others.jenkins.Jenkins;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017-6-9.
 */
@Controller
@RequestMapping
public class LoginUtil {

    Logger logger = LoggerFactory.getLogger(LoginUtil.class);


    public static boolean valid(HttpServletRequest request) {
        String g = SessionUtil.gitname(request);
        String jen = SessionUtil.jenkinsname(request);
        String jp = SessionUtil.jp(request);
        String gp = SessionUtil.gp(request);

        if (StringUtils.isBlank(g) || StringUtils.isBlank(jen) ||
                StringUtils.isBlank(jp) || StringUtils.isBlank(gp)
                ) {
            return true;
        }

        String login = Jenkins.addJenkins(jen, jp);
        if (StringUtils.isBlank(login)) {
            GitUtil.addCre(g, gp);
            return false;
        } else
            return true;
    }
}
